//
//  TeacherDetailViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/12/8.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "TeacherDetailViewController.h"
#import "FamousTeacherTableViewCell.h"
#import "NewsTalkViewController.h"

@interface TeacherDetailViewController ()
@property (nonatomic,copy) NSString *teacherContent;
@end

@implementation TeacherDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([FamousTeacherTableViewCell class]) bundle:nil] forCellReuseIdentifier:@"FamousTeacherTableViewCell"];
    [self creatDataList];
    self.title = @"与时名师";
    [self creatFootView];
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = [UIColor whiteColor];
}
- (void)creatFootView{
    UIView *footView = [[UIView alloc]init];
    footView.frame = CGRectMake(0, kScreenH - 64 - 60, kScreenW, 60);
    footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footView];
    
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(20, 5, kScreenW - 40, 50);
    [button setTitle:@"飞鸽传书" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.backgroundColor = KBACKNAVIGATIONCOLOR;
    button.layer.cornerRadius = 5;
    [button addTarget:self action:@selector(sendFeiBook) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:button];
}
- (void)sendFeiBook{
    NewsTalkViewController *newsTalkVC = [[NewsTalkViewController alloc]init];
    newsTalkVC.friendId = self.famousTeacherInfo.teacherId;
    [self.navigationController pushViewController:newsTalkVC animated:YES];
}
- (void)creatDataList{
//    self.teacherContent = [NSString stringWithFormat:@"联系方式：%@\n\n认证情况：%@\n\n人物介绍：%@\n\n",self.famousTeacherInfo.phone,self.famousTeacherInfo.des,self.famousTeacherInfo.context];
    self.teacherContent = [NSString stringWithFormat:@"认证情况：%@\n\n人物介绍：%@\n\n",self.famousTeacherInfo.des,self.famousTeacherInfo.context];
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!indexPath.section) {
        FamousTeacherTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"FamousTeacherTableViewCell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.famousTeacherInfo = self.famousTeacherInfo;
        return cell;
    }
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
       
        UILabel *label = [[UILabel alloc]init];
        label.textColor = KTEXTMAINCOLOR;
        label.tag = 1000;
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize:15];
        [cell.contentView addSubview:label];
    }
    UILabel *label = [cell.contentView viewWithTag:1000];
    label.frame = CGRectMake(10, 20, kScreenW - 20, [Global getSizeOfString:self.teacherContent maxWidth:kScreenW - 20 maxHeight:CGFLOAT_MAX withFontSize:15].height);
    label.text = self.teacherContent;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (!indexPath.section) {
        return 70;
    }
    return [Global getSizeOfString:self.teacherContent maxWidth:kScreenW - 20 maxHeight:CGFLOAT_MAX withFontSize:15].height + 40;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectZero;
    view.backgroundColor = KBACKGROUNDCOLOR;
    
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
